<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>产品检测</title>
    <link rel="stylesheet" href="../../../../public/dist/css/layui.css">
    <link rel="stylesheet" href="../../../../public/font/iconfont.css">
    <link rel="stylesheet" href="../../../../css/twocss/commit.css">
</head>

<body>
    <form class="layui-form" action="">

        <div class="select common">
            <div class="select-title">查询条件</div>

            <div class="select-con">
                <div class="layui-form-item">
                    <div class="select-hand-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">检测日期:</label>
                            <input type="text" class="layui-input" id="date1">
                            <div style="margin:0 10px;">至</div>
                            <input type="text" class="layui-input" id="date2">
                        </div>
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:95px;">产品名称:</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input  Suppliername">
                        </div>
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">检测单号:</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input   Purchaseorder">
                        </div>
                    </div>
                </div>

                <div class="select-btn">
                    <div class="layui-bg-green comquery   Rawquery">查询</div>
                    <div class="layui-bg-green comquery   reset ">重置</div>
                </div>
            </div>
        </div>
    </form>

    <div class="common-padding">
        <table class="layui-hide" id="testproduction" lay-filter="testdome"></table>
    </div>

</body>




<!-- 检测单 -->
<script type="text/html" id="Detectionsingled">
    <div class="select common ">
        <ul class="basis-h">

            <li>
                <label>检测日期:</label>
                <p>
                    <input type="text" id="test1" placeholder="2019-01-01">
                </p>
            </li>

            <li>
                <label>检测重量(KG):</label>
                <p>
                    <input type="text" class="Theweight">
                </p>
            </li>
            <li>
                <label>检测地点:</label>
                <p>
                    <input type="text" class="places">
                </p>
            </li>
            <li>
                <label>检测机构:</label>
                <p>
                    <input type="text" class="institutions">
                </p>
            </li>

            <li>
                <label>检测项目:</label>
                <p>
                    <input type="text" class="project">
                </p>
            </li>

            <li>
                <label>检测依据:</label>
                <p>
                    <input type="text" class="Onthebasisof">
                </p>
            </li>
            <li>
                <label>检测结果:</label>
                <p class="Shelflife">
                    <input type="text" class="Theresultsof">
                </p>
            </li>

            <div>
                <li>
                    <label>检测结论:</label>
                    <p>
                        <select class="Namerawmaterials">
                                    <option value="">---请选择---</option>
                                    <option value="2">合格</option>
                                    <option value="3">不合格</option>
                        </select>
                    </p>
                </li>
            </div>


            <div>
                <li>
                    <label></label>
                    <p class="empty-h">
                    </p>
                </li>
                <li>
                    <p class="empty-h" style="width:200px;">
                        <button type="button" class="layui-btn  layui-btn-sm  determine" style="margin-left:90px;">
                                          确定
                            </button>
                        <button type="button" class="layui-btn  layui-btn-sm  cancels">
                                          取消
                            </button>
                    </p>
                </li>
            </div>
        </ul>
    </div>

</script>




<!-- 里面的查看 -->
<script type="text/html" id="More">
    {{# if(d.result =="1"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="detection">检测</a> {{# } else { }}
    <a class="layui-btn layui-btn-primary layui-btn-xs">已检测</a> {{# } }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
</script>


<!-- 查看的内容 -->
<script type="text/html" id="contentquery">
    <div class="select common">

        <div class="select-title" style="border-bottom:0px;background-color: #f3f3f3;">
            基本信息
        </div>
        {{each list}}
        <ul class="basis-h">

            <li>
                <label>负责人:</label>
                <p>{{$value.person}}</p>
            </li>
            <li>
                <label>原辅料名称:</label>
                <p>{{$value.productname}}</p>
            </li>
            <li>
                <label>检测日期:</label>
                <p>{{$value.orderdate}}</p>
            </li>
            <li>
                <label>采购批次:</label>
                <p>{{$value.batch}}</p>
            </li>
            <li>
                <label>检测地点:</label>
                <p>{{$value.testlocation}}</p>
            </li>
            <li>
                <label>检测机构:</label>
                <p>{{$value.testorgnazation}}</p>
            </li>
            <li>
                <label>抽样基数(KG):</label>
                <p>{{$value.testnum}}</p>
            </li>
            <li>
                <label>检测重量(KG):</label>
                <p>{{$value.testweight}}</p>
            </li>
            <li style="margin-left: 25px;">
                <label>检测依据:</label>
                <p>{{$value.testbasic}}</p>
            </li>
            <li>
                <label>采购单号:</label>
                <p style="width: 190px;">{{$value.ordercode}} </p>
            </li>
            <li>
                <label>检测结论:</label> {{if $value.testresult == "1"}}
                <p style="text-align: center;">待检测</p>
                {{else if $value.testresult == "2" }}
                <p style="text-align: center;">检测合格</p>
                {{else}}
                <p style="text-align: center;">不合格</p>
                {{/if}}
            </li>

        </ul>
        <div style="padding:10px  0  0 10px;">检测信息</div>
        <table class="layui-table">
            <thead>
                <tr>
                    <!-- <th>抽样基数(KG)</th>
                    <th>检测重量(KG)</th> -->
                    <th>检测项目</th>
                    <th>检测结果</th>
                    <!-- <th>检测结论</th> -->
                </tr>
            </thead>
            <tbody>
                {{each list[0].prolist}}
                <tr>
                    <td style="text-align: center;">{{$value.testnamelist}}</td>
                    <td style="text-align: center;">{{$value.resultlist}}</td>
                </tr>
                {{/each}}
            </tbody>
        </table>
        {{/each}}
    </div>

</script>


<script src="../../../../js/common/jquery.min.js"></script>
<script src="../../../../js/common/api.js"></script>
<script src="../../../../public/dist/layui.js" charset="utf-8"></script>
<script src="../../../../js/common/template-web.js"></script>
<script>
    layui.use(['table', "laydate", "util", "layer"], function() {
        var $ = layui.jquery,
            table = layui.table,
            util = layui.util,
            layer = layui.layer,
            laydate = layui.laydate;

        laydate.render({
            elem: '#date1' //指定元素 
        });
        laydate.render({
            elem: '#date2' //指定元素
        });

        //监听表格里面按钮
        table.on('tool(testdome)', function(obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event;
            if (layEvent === 'detail') { //查看
                Toview(data.id);
                return
            }
            /*检测*/
            if (layEvent === 'detection') {
                // Detectionsinglesingle(data.id);
                window.location.href = "./newpage/detectionNew.html?id=" + data.id;
                return
            }
        });


        function Toview(tt) {
            layer.open({
                type: 1,
                title: "查看",
                shadeClose: true, //是否点击遮罩关闭
                anim: 5, //弹出动画
                scrollbar: false, //窗口外滚动条是否出现
                skin: 'layui-layer-rim', //加上边框
                area: ['900px', '440px'], //宽高
                content: '<div class="ssss"></div>',
                success: function(layero, index) {

                    noAjax('ordPurchase/getOrdTestOne', {
                        id: tt
                    }, "GET").done(function(resp) {

                        $.each(resp.list, function(index, item) {
                            if (item.orderdate == null || item.orderdate == "") {
                                item.orderdate = "";
                            } else {
                                item.orderdate = times(item.orderdate);
                            }
                        });
                        var resultlist = [];
                        var testnamelist = [];
                        var prolist = [];
                        // 判断是不是数组
                        var ss = resp.list[0].result.indexOf("[");

                        if (ss == 0) {
                            resultlist = JSON.parse(resp.list[0].result);
                        } else {
                            resultlist.push(resp.list[0].result);
                        }
                        if (ss == 0) {
                            testnamelist = JSON.parse(resp.list[0].testname);
                        } else {
                            testnamelist.push(resp.list[0].testname);
                        }
                        for (var i = 0; i < resultlist.length; i++) {
                            prolist.push({
                                'resultlist': resultlist[i],
                                'testnamelist': testnamelist[i]
                            })
                        }
                        resp.list[0].prolist = prolist;
                        console.log(resp);

                        var html = template("contentquery", resp);
                        $(".ssss").html(html);
                        // $(".ssss").html(prolist);

                    }).fail(function(err) {
                        console.log(err)

                    });
                }
            });
        }

        function times(t) {
            return t = t.split("T")[0];
        }


        //获取列表
        var tableIns = table.render({
            elem: '#testproduction',
            url: base + "ordPurchase/getOrdTest",
            method: "GET",
            where: {
                productclass: "2"
            },
            headers: {
                Authorization: "Bearer" + " " + sessions
            },
            request: {
                limitName: '10'
            },
            limits: [10, 20],
            parseData: function(res) { //res 即为原始返回的数据
                console.log(res)
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "totalNum": res.pageBean.totalNum, //解析数据长度
                    "lists": res.pageBean.lists //解析数据列表
                };
            },
            request: {
                pageName: 'currentPage',
                limitName: 'pageSize'
            },
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 10000, //成功的状态码，默认：0
                msgName: null, //状态信息的字段名称，默认：msg
                countName: 'totalNum', //数据总数的字段名称，默认：count
                dataName: 'lists', //数据列表的字段名称，默认：data
            },
            cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                ,
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['prev', 'page', 'next', 'skip', 'count'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    ,
                groups: 5 //只显示 1 个连续页码
                    ,
                first: true //不显示首页
                    ,
                last: true //不显示尾页
                    ,
                prev: "上一页",
                next: "下一页",
                theme: "#c81623",
            },
            // height: 'full-20',//满高
            cols: [
                [{
                        title: '编号',
                        type: 'numbers',
                        fixed: 'left'
                    }, {
                        field: 'orderdate',
                        title: '检测日期',
                        sort: true,
                        fixed: 'left',
                        minWidth: 120,
                        align: "center",
                        templet: function(d) {
                            var numv = null;
                            if (d.orderdate == "" || d.orderdate == null) {
                                numv = " ";
                            } else {
                                numv = d.orderdate = layui.util.toDateString(d.orderdate, 'yyyy-MM-dd');
                            }
                            return numv
                        },
                    }, {
                        field: 'ordercode',
                        align: "center",
                        title: "检测单号",
                        sort: true,
                        minWidth: 160,
                    }, {
                        field: 'productname',
                        title: '产品名称',
                        minWidth: 120,
                        sort: true,
                        align: "center",
                    }, {
                        field: 'batch',
                        title: '生产批次',
                        align: "center",
                        minWidth: 20,
                        sort: true
                    }, {
                        field: 'testresult',
                        title: '检测结论',
                        minWidth: 120,
                        align: "center",
                        templet: function(d) {
                            var num = null;
                            console.log(d.testresult)
                            if (d.testresult == "1") {
                                num = "待检测"
                                return num
                            }

                            if (d.testresult == "2" || d.testresult == "合格") {
                                num = "合格"
                                return num
                            }
                            if (d.testresult == "3" || d.testresult == "不合格") {
                                num = "不合格"
                                return num
                            }
                        }
                    },
                    // {
                    //     field: 'result',
                    //     title: '检测结果',
                    //     align: "center",
                    //     minWidth: 120
                    // }, 
                    {
                        field: 'wealth',
                        width: 137,
                        title: '更多',
                        minWidth: 80,
                        align: "center",
                        fixed: 'right',
                        toolbar: '#More',
                    }
                ]
            ]
        });



        /*查询*/
        $(".Rawquery").click(function() {
            if ($("#date1").val() == "" && $("#date2").val() == "" && $(".Suppliername").val() == "" && $(".Purchaseorder").val() == "") {
                layer.msg('请输入查询条件！', {
                    time: 1000,
                    offset: 't',
                });
                return
            }
            if ($("#date1").val() != "") {
                if ($("#date2").val() == "") {
                    layer.msg('请选择时间段！', {
                        time: 1000,
                        offset: 't',
                    });
                    return
                }
            }

            if ($("#date2").val() != "") {
                if ($("#date1").val() == "") {
                    layer.msg('请选择时间段！', {
                        time: 1000,
                        offset: 't',
                    });
                    return
                }
            }
            datelist = {
                    orderdateq: $("#date1").val() + " " + "00:00:00",
                    orderdateh: $("#date2").val() + " " + "00:00:00",
                    productname: $(".Suppliername").val(),
                    ordercode: $(".Purchaseorder").val(),
                    productclass: 2
                }
                // console.log(datelist)
            tableIns.reload({
                where: datelist,
                page: {
                    curr: 1, //重新从第 1 页开始
                    layout: ['prev', 'page', 'next', 'skip', 'count']
                },
            })
        })



        /*重置*/
        $(".reset").click(function() {
            $("#date1").val("");
            $("#date2").val("");
            $(".Suppliername").val("");
            $(".Purchaseorder").val("");
            tableIns.reload({
                where: {
                    productclass: 2
                },
                page: {
                    curr: 1, //重新从第 1 页开始
                    layout: ['prev', 'page', 'next', 'skip', 'count']
                },
            })
        })


        //检测单
        function Detectionsinglesingle(ids) {

            layer.open({
                type: 1,
                title: "检测单",
                shadeClose: true, //是否点击遮罩关闭
                anim: 5, //弹出动画
                scrollbar: false, //窗口外滚动条是否出现
                skin: 'layui-layer-rim', //加上边框
                area: ['760px', '400px'], //宽高
                content: '<div  class="ssss"></div>',
                success: function(layero, index) {
                    var html = template("Detectionsingled");
                    $(".ssss").html(html);

                    //检测时间
                    laydate.render({
                        elem: '#test1' //指定元素
                    });

                    ///检测单
                    single(ids);
                }
            })
        }


        function single(e) {
            //取消
            $(".cancels").click(function() {
                layer.closeAll();
            })

            //确定
            $(".determine").click(function() {

                if ($("#test1").val() == "") {
                    layer.msg('选择检测日期', {
                        time: 1000,
                        offset: 't',
                    });
                    return
                }

                if ($(".Theweight").val() == "") {
                    layer.msg('请输入检测重量', {
                        time: 1000,
                        offset: 't',
                    });
                    return
                }

                if ($(".places").val() == "") {
                    layer.msg('请输入检测地点', {
                        time: 1000,
                        offset: 't',
                    });
                    return
                }

                if ($(".institutions").val() == "") {
                    layer.msg('请输入检测机构', {
                        time: 1000,
                        offset: 't',
                    });
                    return
                }

                if ($(".Onthebasisof").val() == "") {
                    layer.msg('请输入检测依据', {
                        time: 1000,
                        offset: 't',
                    });
                    return
                }


                if ($(".project").val() == "") {
                    layer.msg('请输入检测项目', {
                        time: 1000,
                        offset: 't',
                    });
                    return
                }

                if ($(".Theresultsof").val() == "") {
                    layer.msg('请输入检测结果', {
                        time: 1000,
                        offset: 't',
                    });
                    return
                }

                if ($(".Namerawmaterials").val() == "") {
                    layer.msg('请选择检测结论', {
                        time: 1000,
                        offset: 't',
                    });
                    return
                }


                var Detectionsingle = {
                    id: e,
                    orderdate: $("#test1").val() + " " + "00:00:00",
                    testweight: $(".Theweight").val(),
                    testlocation: $(".places").val(),
                    testorgnazation: $(".institutions").val(),
                    testbasic: $(".Onthebasisof").val(),
                    testname: $(".project").val(),
                    result: $(".Theresultsof").val(),
                    testresult: $(".Namerawmaterials").val()
                }

                console.log(Detectionsingle);
                // return
                handleAjax("ordPurchase/updateOrdTest", Detectionsingle, "POST").done(function(resp) {
                    console.log(resp)
                    layer.msg("检测成功", {
                        icon: 1,
                        time: 1000,
                    });
                    setTimeout(function() {
                        layer.closeAll();
                    }, 1500)
                    window.location.reload();
                }).fail(function(err) {
                    console.log(err)
                });
            })
        }



    })
</script>

</html>